package com.ddf.publics.service.impl;

import com.ddf.publics.config.Utill;
import com.ddf.publics.entity.UserInfo;
import com.ddf.publics.service.PayPwdService;
import com.ddf.publics.service.UserInfoService;
import com.ddf.publics.tool.Constant;
import com.ddf.publics.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayPwdServiceImpl implements PayPwdService {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private RedisUtil redisUtil;
    /***
     * @description 判断交易密码
     * @author jerry
     * @date 2020/6/30 16:06
     * @params [userId, pwd]
     * @return java.lang.String
     */
    @Override
    public int payPwd(int userId,String pwd){
        UserInfo userInfo=userInfoService.userInfoList(userId);
        //密码输入5次以上错误不能支付
        Integer paynum = (Integer) redisUtil.get("pay:" + userId);
        if(paynum!=null&&paynum>=5){
            return Constant.PAY_LOCK;
        }
        //密码错误
        if(!userInfo.getPayPwd().equals(pwd)){
            redisUtil.incr("pay:"+userId,1, Utill.TodaySeconds());
            return Constant.PAY_NO;
        }
        redisUtil.del("pay:"+userId);
        return Constant.PAY_YES;
    }
}
